package five;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.rabbitmq.client.Delivery;
import utils.RabbitMQUtils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class ReceiveLogs01 {

    //交换机名称
    private static final String EXCHANGE_NAME = "logs";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMQUtils.getChannel();
        //声明一个交换机
        //交换机名称,交换机类型
        channel.exchangeDeclare(EXCHANGE_NAME,"fanout");
        //声明一个临时队列
        String queueName = channel.queueDeclare().getQueue();
        //绑定交换机和队列
        channel.queueBind(queueName,EXCHANGE_NAME,"");
        System.out.println("等待接收消息 把接收到的消息打印在屏幕上");

        DeliverCallback deliverCallback = (consumerTag, message) ->{
            System.out.println("控制台打印接收到的消息:" + new String(message.getBody()));
        };
        //接收消息
        channel.basicConsume(queueName,true,deliverCallback,consumerTag -> {});

    }
}
